
$(document).ready(function() {
	
	$("#btnSendCode-cph1").click(function(e) {
        var param = {
			captchaType: 1,
			captchaWay: 0,
			captchaUse: 602,
		};
		AQ.callAQ("applyCaptcha.do", param, function(result) {
			var dom = $("#btnSendCode-cph1");
			countDown(dom[0], 60);
		}, function(err, code){
			Utils.msgDialog(err + "["+ code +"]");
		});
    });
	
	$("#btnSendCode-cph2").click(function(e) {
		var phone1 = $.trim($("#phone-1").text());
        var phone = $("#phone-2").val();
		var phoneReg = /^[1][34578][0-9]{9}$/;
		if(!phoneReg.test(phone)) {
			Utils.msgDialog("×  手机号格式不正确！");
			return false;
		} else if(phone == phone1) {
			Utils.msgDialog("×  新手机号不能和原手机号相同！");
			return false;
		}
		
        var param = {
			captchaType: 1,
			captchaWay: phone,
			captchaUse: 603,
		};
		AQ.callAQ("applyCaptcha.do", param, function(result) {
			countDown($("#btnSendCode-cph2")[0], 60);
			$("#phone-2").prop("readOnly", true);
		}, function(err, code){
			Utils.msgDialog(err + "["+ code +"]");
		});
    });
	
	$("#submit-cph").click(function(e) {
        var code1 = $("#cph-code1").val();
		var code2 = $("#cph-code2").val();
		var codeReg = /^[0-9]{6}$/;
		if(!codeReg.test(code1)) {
			Utils.msgDialog("×  原手机验证码格式不正确！");
			return false;
		} else if(!codeReg.test(code2)) {
			Utils.msgDialog("×  新手机验证码格式不正确！");
			return false;
		}
		
        var param = {
			captchaCode: code1,
			newCaptchaCode: code2,
		};
		AQ.callAQ("changePhone.do", param, function(result) {
			Utils.msgDialog("手机号更换成功！");
			location.replace("user-center.html");
		}, function(err, code){
			Utils.msgDialog(err + "["+ code +"]");
		});
    });
	
});